package com.hmdp.utils;

import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


// 拦截需要登录的路径
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 1.看ThreadLocal是否有数据需要拦截
        if(UserHolder.getUser()==null){
            // 2.拦截
            response.setStatus(401);
            return false;
        }
        // 3.反之就放行
        return true;
    }
}
